package nirvana.core.domains.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import javax.persistence.Entity;
import javax.persistence.MappedSuperclass;
import lombok.Data;
import lombok.EqualsAndHashCode;
import nirvana.core.validation.Validatable;
import nirvana.core.validation.ValidationResult;
import nirvana.core.validation.ValidatorUtils;

import javax.persistence.Id;

/**
 * Entity 基础类
 *
 * @author linkanyway
 * @version 1.0
 * @date 2024/04/14 22:51
 */
@MappedSuperclass
@Data
@EqualsAndHashCode(callSuper = false)
public abstract class BaseEntity<T extends Model<?>> extends Model<T> implements Validatable {


    /**
     * 业务编号
     * 框架内使用雪花 id
     */
    @Id
    @TableId(type = IdType.ASSIGN_ID)
    @Excel(name = "业务编号")
    @Column(type = MySqlTypeConstant.BIGINT,
            length = 20,
            isNull = false,
            comment = "id")
    private Long id;

    /**
     * 验证数据
     *
     * @return 验证结果
     */
    @Override
    public ValidationResult valid() {
        return ValidatorUtils.validate (this);
    }
}
